package com.ftg.learn;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author Guo
 * @date 2022/4/19
 */
public class test01 {

    @Test
    public void AutomaticGeneration() {
        String url = "jdbc:mysql://139.159.146.255:3306/youxuemall";
        String username = "root";
        String password = "123456";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("mallCommon") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("E:\\javaLearn\\test111"); // 指定输出目录
//                            .outputDir("D:\\workspace\\javaspace\\first-project-2113\\mall-admin\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.ftg.learn") // 设置父包名
                            .moduleName("mall");// 设置父包模块名
                    //.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(Arrays.asList("pms_brand","pms_feight_template","pms_product","pms_product_attribute","pms_product_attribute_category",
                                    "pms_product_attribute_value","pms_product_category","pms_product_category_attribute_relation","pms_sku_stock")) // 设置需要生成的表名
                            .addTablePrefix(""); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
